/** 首页栏目 js 加载 **/
layui.use(['jquery', 'setter', 'element', 'layer', 'form', 'table'],
    function () {

      var $ = layui.jquery
          , element = layui.element
          , layer = layui.layer
          , setter = layui.setter;

      var form = layui.form;
      var table = layui.table;
      /** 我的工作台 **/
      if ($('#myconsole')) {
        var contentObjectId = "myconsole";
        var colunmAlias = "wdgzt";//栏目别名
        var clickAddClass = "clickAdd";//添加按钮的class
        var clickDeleteClass = "clickDelete";//删除按钮的class
        var checkedAppId = "checkedApp_mycon";//弹框中我的应用的部分的 id
        var nonCheckAppId = "nonCheckApp_mycon";//弹框中未选择应用部分的 id
        var addId = "addid_mycon";// 新增/删除按钮的id

        //首页及弹框资源
        getIndexUserRes(contentObjectId, colunmAlias, addId, checkedAppId,
            nonCheckAppId, clickAddClass, clickDeleteClass);

        //移除阴影
        // moveMask('#addContent_mycon');

        //添加
        addRes(clickAddClass, checkedAppId, clickDeleteClass);
        //删除
        deleteRes(clickDeleteClass, nonCheckAppId, clickAddClass);
        //保存
        saveRes(contentObjectId, colunmAlias, checkedAppId, addId,
            'addContent_mycon');
      }

      //我的控制台-点击新增/删除按钮打开弹框
      $(document).on("click", '#addid_mycon', function () {
        openAddContent('addContent_mycon');
      });

      /** 作训体系 **/
      if ($('#myconsole_zxtx')) {
        var contentObjectId = "myconsole_zxtx";
        var colunmAlias = "zxtx";//栏目别名
        var clickAddClass = "clickAdd_zxtx";//添加按钮的class
        var clickDeleteClass = "clickDelete_zxtx";//删除按钮的class
        var checkedAppId = "checkedApp_zxtx";//弹框中我的应用的部分的 id
        var nonCheckAppId = "nonCheckApp_zxtx";//弹框中未选择应用部分的 id
        var addId = "addid_zxtx";// 新增/删除按钮的id

        //首页及弹框资源
        getIndexUserRes(contentObjectId, colunmAlias, addId, checkedAppId,
            nonCheckAppId, clickAddClass, clickDeleteClass);
        //添加
        addRes(clickAddClass, checkedAppId, clickDeleteClass);
        //删除
        deleteRes(clickDeleteClass, nonCheckAppId, clickAddClass);
        //保存
        saveRes(contentObjectId, colunmAlias, checkedAppId, addId,
            'addContent_zxtx');
      }
      //作训体系-点击新增/删除按钮打开弹框
      $(document).on("click", '#addid_zxtx', function () {
        openAddContent('addContent_zxtx');
      });

      /** 政工体系 **/
      if ($('#myconsole_zgtx')) {
        var contentObjectId = "myconsole_zgtx";
        var colunmAlias = "zgtx";//栏目别名
        var clickAddClass = "clickAdd_zgtx";//添加按钮的class
        var clickDeleteClass = "clickDelete_zgtx";//删除按钮的class
        var checkedAppId = "checkedApp_zgtx";//弹框中我的应用的部分的 id
        var nonCheckAppId = "nonCheckApp_zgtx";//弹框中未选择应用部分的 id
        var addId = "addid_zgtx";// 新增/删除按钮的id

        //首页及弹框资源
        getIndexUserRes(contentObjectId, colunmAlias, addId, checkedAppId,
            nonCheckAppId, clickAddClass, clickDeleteClass);
        //添加
        addRes(clickAddClass, checkedAppId, clickDeleteClass);
        //删除
        deleteRes(clickDeleteClass, nonCheckAppId, clickAddClass);
        //保存
        saveRes(contentObjectId, colunmAlias, checkedAppId, addId,
            'addContent_zgtx');
      }
      //政工体系-点击新增/删除按钮打开弹框
      $(document).on("click", '#addid_zgtx', function () {
        openAddContent('addContent_zgtx');
      });

      /** 待办事宜 **/
      if ($('#pendingContent')) {
        $.ajax({
          type: 'get',
          url: serverPath.workflowPath + '/workflow/task/list/pendingMatters',
          dataType: 'json',
          // async: false,
          success: function (data) {
            $('#pendingContent').html('');
            if (data != null && data.data != null && data.data.length > 0) {
              var num = data.data.length < 5 ? data.data.length : 5;
              for (var i = 0; i < num; i++) {
                var content =
                    '<li>'
                    + '<a href="' + serverPath.workflowPath
                    + setter.workflowLinkPath + 'task/view/toStart?taskId='
                    + data.data[i].id + '&instanceId='
                    + data.data[i].processInstanceId + '" target="_blank">'
                    + '<p>'
                    + '<span class="tit">' + data.data[i].subject + '</span>'
                    + '<i class="verticalLine"></i>'
                    + '<cite>' + dateChange(data.data[i].createTime) + '</cite>'
                    + '</p>'
                    // +       '<div class="rightInfor">'
                    // +           '<i class="iconfont iconicon_people_fill"></i>'
                    // +           '<span>' + data.data[i].creator +'</span>'
                    // +       '</div>'
                    + '</a>'
                    + '</li>';
                $('#pendingContent').append(content);
              }

            }

          }, error: function (data) {
          }
        });
      }

      /** 已办事宜 **/
      if ($('#alreadyContent')) {
        $.ajax({
          type: 'get',
          url: serverPath.workflowPath
              + '/workflow/processRun/list/alreadyMatter',
          dataType: 'json',
          // async: false,
          success: function (data) {
            $('#alreadyContent').html('');
            if (data != null && data.data != null && data.data.length > 0) {
              var num = data.data.length < 5 ? data.data.length : 5;
              for (var i = 0; i < num; i++) {
                var content =
                    '<li>'
                    + '<a href="' + serverPath.systemPath
                    + setter.workflowLinkPath + 'processRun/view/info?runId='
                    + data.data[i].runId
                    + '&prePage=myFinishedTask" target="_blank">'
                    + '<p>'
                    + '<span class="tit">' + data.data[i].subject + '</span>'
                    + '<i class="verticalLine"></i>'
                    + '<cite>' + dateChange(data.data[i].createTime) + '</cite>'
                    + '</p>'
                    // +       '<div class="rightInfor">'
                    // +           '<i class="iconfont iconicon_people_fill"></i>'
                    // +           '<span>' + data.data[i].creator + '</span>'
                    // +       '</div>'
                    + '</a>'
                    + '</li>';

                $('#alreadyContent').append(content);
              }
            }

          },
          error: function (data) {
          }
        });
      }

      /** 统计图 **/
      var isFirst = true;
      var type;
      $("#type").change(function () {
        var beginTime;
        var endTime;
        type = $(this).children('option:selected').val();
        isFirst = false;
        if (type == "三年柱形图") {
          var year = new Date().getFullYear();
          beginTime = year - 2 + "-01-01";
          endTime = year + "-12-31";
        } else {
          var date = new Date();
          var year = date.getFullYear();
          var month = date.getMonth() + 1;
          var day = date.getDate();
          beginTime = year + "-01-01";
          endTime = year + "-" + month + "-" + day;
        }
        getChartData(beginTime, endTime, type);

      });
      if (isFirst) {
        type = "三年柱形图";
        var year = new Date().getFullYear();
        var beginTime = year - 2 + "-01-01";
        var endTime = year + "-12-31";
      }

      var myChart = echarts.init(document.getElementById("chart1Bar"));
      var chart2Bar = echarts.init(document.getElementById("chart2Bar"));
      var chart2Pie = echarts.init(document.getElementById("chart2Pie"));
      myChart.on('click', function (params) {
        console.log(params);
        if (type == "三年统计图") {

        }

      });
      chart2Bar.on('click', function (params) {
        console.log(params);
      });
      chart2Pie.on('click', function (params) {
        console.log(params);
      });
      getChartData(beginTime, endTime, type);

      function getChartData(beginTime, endTime, type) {
        $.ajax({
          url: serverPath.workflowPath
              + '/qbdms/modelQualityStatistics/getChartData',
          data: {
            "beginTime": beginTime,
            "endTime": endTime,
            "statisticalMethods": type
          },
          type: 'post',
          dataType: 'json',
          async: false,
          success: function (res) {
            $("#chart1Bar").hide();
            $("#chart2Bar").hide();
            $("#chart2Pie").hide();
            if (type == "三年柱形图") {
              $("#chart1Bar").show();
              firstEchart(res.data[0]);
              return;
            }
            if (type == "研制型号按原因统计") {
              echartBar(res.data[0]);
              echartPie(res.data[1]);
              $("#chart2Bar").show();
              $("#chart2Pie").show();
              return;
            }
            if (type == "批产型号按原因统计") {
              echartBar(res.data[0]);
              echartPie(res.data[1]);
              $("#chart2Bar").show();
              $("#chart2Pie").show();
              return;
            }

            if (type == "研制型号按阶段统计") {
              echartBar(res.data[0]);
              echartPie(res.data[1]);
              $("#chart2Bar").show();
              $("#chart2Pie").show();
              return;
            }
            if (type == "批产型号按阶段统计") {
              echartBar(res.data[0]);
              echartPie(res.data[1]);
              $("#chart2Bar").show();
              $("#chart2Pie").show();
              return;
            }
            echartBar(res.data[0]);
            echartPie(res.data[1]);
            $("#chart2Bar").show();
            $("#chart2Pie").show();
            return;

          },
        })

      }

      function firstEchart(data) {
        // 基于准备好的dom，初始化echarts实例
        var option = {
          animation: false,
          color: ['#5B8FF9', '#f6bd16', '#5ad8a6', '#e86452', '#5d7092',
            '#ff9845', '#6dc8ec', '#ff99c3', '#1e9493', '#945fb9'],
          title: {
            // text: data.title,
            x: '20',
            y: 'top'
          },
          grid: {
            top: 110
          },
          tooltip: {
            axisPointer: {
              type: 'cross',
              crossStyle: {
                color: '#999'
              }
            }
          },
          // toolbox: {
          //   feature: {
          //     saveAsImage: {type: 'JPEG'}
          //   }
          // },
          legend: {
            orient: 'horizontal',
            left: '20',
            top: '30',
            data: data.legend
          },
          xAxis: [
            {
              type: 'category',
              data: data.xAxis,
              axisPointer: {
                type: 'shadow'
              }
            }
          ],
          yAxis: [
            {
              type: 'value',
              splitLine: {
                show: true,
                lineStyle: {
                  type: "dashed"
                }
              },
              name: '数量',
              // min: 0,
              // max: 250,
              // interval: 50,
              nameLocation: 'middle',
              nameTextStyle: {
                color: '#00A8FF',
                verticalAlign: 'bottom',
                padding: [20, 20, 10, 20]
              },
              axisLine: {
                lineStyle: {
                  width: 0
                }
              },
              axisTick: {
                show: false
              },
              axisLabel: {
                formatter: '{value} '
              },
              axisLabel: {
                textStyle: {
                  color: '#00A8FF'
                }
              }
            },
            {
              type: 'value',
              splitLine: {
                show: true,
                lineStyle: {
                  type: "dashed"
                }
              },
              name: '百分比',
              min: 0,
              max: 100,
              interval: 5,
              axisLabel: {
                formatter: '{value} %'
              },
              axisTick: {
                show: false
              },
              nameRotate: -90,
              nameLocation: 'middle',
              nameTextStyle: {
                color: '#000000',
                verticalAlign: 'bottom',
                padding: [120, 20, 30, 20]
              },
              axisLine: {
                lineStyle: {
                  width: 0
                }
              }
            }
          ],
          series: data.data
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.clear();
        myChart.setOption(option);
      }

      function echartBar(data) {
        var option = {
          animation: false,
          title: {
            // text: data.title,
            x: 'left',
            y: 'top'
          },
          color: ['#5B8FF9'],
          xAxis: [{
            type: 'category',
            data: data.xtitlelist,
          }],
          // toolbox: {
          //   feature: {
          //     saveAsImage: {type: 'JPEG'}
          //   }
          // },
          yAxis: [{
            type: 'value',
            name: '数量',
            nameLocation: 'middle',
            nameTextStyle: {
              verticalAlign: 'bottom',
              padding: [20, 20, 30, 440]
            },
            axisLine: {
              lineStyle: {
                width: 0
              }
            }

          }],

          series: [{
            name: '直接访问',
            type: 'bar',
            data: data.datalist,
            itemStyle: {
              normal: {
                label: {
                  show: true, //开启显示
                  textStyle: { //数值样式
                    color: 'black',
                    fontSize: 16
                  }
                }
              }
            }
          }]
        };
        // 使用刚指定的配置项和数据显示图表。
        chart2Bar.clear();
        chart2Bar.setOption(option);
      }

      function echartPie(data) {
        var optionPie = {
          color: ['#5B8FF9', '#5AD8A6', '#5D7092', '#F6BD16', '#E86452',
            '#6DC8EC', '#945FB9', '#FF9845', '#1E9493', '#FF99C3'],
          animation: false,
          title: {
            // text: data.title,
            left: 'left'
          },
          legend: {
            icon: 'circle',
            orient: 'horizontal',
            left: 'center',
            bottom: '50px',
            data: data.xtitlelist
          },
          // toolbox: {
          //   feature: {
          //     saveAsImage: {type: 'JPEG'}
          //   }
          // },
          series: [{
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            // center: ['50%', '60%'],
            data: data.datalist,
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              },
              normal: {
                label: {
                  show: true,
                  formatter: '{b} : {c} ({d}%)'
                },
                labelLine: {
                  show: true
                }
              }
            }
          }]
        };
        // 使用刚指定的配置项和数据显示图表。
        chart2Pie.clear();
        chart2Pie.setOption(optionPie);
      }

      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var beginTableTime = year + "-" + month + "-" + day;
      var endTableTime = year + "-" + month + "-" + day;

      loadCount();

      function loadCount() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var beginYear = date.getFullYear() + "-01-01";
        var endYear = year + "-12-31";
        $.ajax({

          url: serverPath.workflowPath
              + '/qbdms/wQbdFalProblemreset/getCountByTime',
          data: {
            "Q_beginTime_DL": beginYear,
            "Q_endTime_DE": endYear
          },
          type: 'post',
          dataType: 'json',
          async: false,
          success: function (res) {
            $("#count").html("本年度质量问题:   " + res.count);
          },
        })
      }

      var fIfreset = "";
      var problemName = "";
      reloadTable();

      function reloadTable() {

        table.render({
          defaultToolbar: [],
          elem: '#wQbdFalProblemresetTable'
          , height: '500px'
          , url: serverPath.workflowPath
              + '/qbdms/wQbdFalProblemreset/list'
          , page: true //开启分页
          , method: 'post'
          , limit: 10
          , autoSort: false //是否排序
          , cols: [[{field: 'fModelname', title: '型号名称', minWidth: '110'}
            , {field: 'fProblemname', title: '质量问题名称', minWidth: '130'}
            , {field: 'fProductname', title: '故障产品名称', minWidth: '110'}
            , {
              field: 'fDetecttime',
              title: '问题发生时间',
              minWidth: '110',
              templet: function (d) {
                return timeData(d.fDetecttime);
              }
            },
            {field: 'fDutydept', title: '问题责任单位', minWidth: '130'},
            {field: 'fProblemrank', title: '问题等级', minWidth: '130'},
            {field: 'fIfreset', title: '是否归零', minWidth: '130'},
            {
              fixed: 'right',
              title: '历史质量问题',
              minWidth: '120',
              toolbar: '#wQbdFalProblemresetRightToolsBar'
            }
          ]]
          , where: {
            "Q_beginTime_DL": beginTableTime,
            "Q_endTime_DE": endTableTime,
            "Q_fIfreset_S": fIfreset,
            "Q_fProblemname_SL": problemName
          }
        });

      }

      function parTime(m) {
        return m < 10 ? '0' + m : m
      }

      function timeData(date, type) {
        if (!date) {
          return "";
        }
        var time = new Date(date * 1);
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        if (type == '1') {
          return y + '-' + parTime(m) + '-' + parTime(d) + ' ' + parTime(h)
              + ':' + parTime(mm) + ':' + parTime(s);
        } else if (type == '2') {
          return parTime(h) + ':' + parTime(mm) + ':' + parTime(s);
        } else if (type == '3') {
          return y;
        } else if (type == '4') {
          return y + '-' + parTime(m);
        } else {
          return y + '-' + parTime(m) + '-' + parTime(d);
        }
      }

      function removeBtnRedClass() {
        $("#today").removeClass("red");
        $("#week").removeClass("red");
        $("#month").removeClass("red");
        $("#year").removeClass("red");
      }

      document.getElementById("today").onclick = function () {
        removeBtnRedClass()
        $(this).addClass("red")
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        beginTableTime = year + "-" + month + "-" + day;
        endTableTime = year + "-" + month + "-" + day;
        reloadTable();
      }
      document.getElementById("week").onclick = function () {
        removeBtnRedClass()
        $(this).addClass("red")
        beginTableTime = getThisWeekDataFirst();
        endTableTime = getThisWeekDataLast();
        reloadTable();
      }
      document.getElementById("month").onclick = function () {
        removeBtnRedClass()
        $(this).addClass("red")
        beginTableTime = currentMonthFirst();
        endTableTime = currentMonthLast();
        reloadTable();
      }
      document.getElementById("year").onclick = function () {
        removeBtnRedClass()
        $(this).addClass("red")
        var date = new Date();
        beginTableTime = date.getFullYear() + "-01-01";
        endTableTime = date.getFullYear() + "-12-31";
        reloadTable();
      }
      document.getElementById("problemName").onkeyup = function () {
        problemName = $("#problemName").val();
        reloadTable();
      }
      $("#fIfreset").change(function () {
        fIfreset = $(this).children('option:selected').val();
        reloadTable();
      });

      table.on('tool(wQbdFalProblemresetTable)', function (obj) {
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
            switch (layEvent) {
              case "history":
                layer.open({
                  type: 2,
                  area: ['80%', '100%'],
                  skin: 'qbdms-layerFormBtn',
                  title: ['关联分析', 'font-size:14px;'],
                  content: serverPath.workflowPath
                      + '/qbdms/wQbdFalProblemreset/view/history?fProductname='
                      + data.fProductname,
                })
                break;
            }
          }
      );

      function currentMonthFirst() {
        var date = new Date();
        date.setDate(1);
        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
            + date.getDate();
      }

      function currentMonthLast() {
        var date = new Date();
        var currentMonth = date.getMonth();
        var nextMonth = ++currentMonth;
        var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
        var oneDay = 1000 * 60 * 60 * 24;
        var lasDate = new Date(nextMonthFirstDay - oneDay);
        return lasDate.getFullYear() + "-" + (lasDate.getMonth() + 1) + "-"
            + lasDate.getDate();

      }

      function getThisWeekDataFirst() {//获得本周周一~周日的年月日
        var date = new Date();
        // 本周一的日期
        date.setDate(date.getDate() - date.getDay() + 1);
        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
            + date.getDate();
      }

      function getThisWeekDataLast() {
        var date = new Date();
        date.setDate(date.getDate() + 6);
        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
            + date.getDate();
      }

      /**
       * 首页资源（我的控制台、作训体系、政工体系）
       */
      function getIndexUserRes(contentObj, columnAlias, addId, checkedAppId,
          nonCheckAppId, clickAddClass, clickDeleteClass) {
        // var resData = null;
        $.ajax({
          type: 'get',
          url: serverPath.systemPath + layui.setter.sysLinkPath
              + 'sysUserColumnRes/userRes',
          dataType: 'json',
          data: {"columnAlias": columnAlias},
          // async: false,
          success: function (data) {
            $("#" + contentObj).html('');//初始化清空
            var userResListContent = '';
            if (data != null && data.data != null) {
              var userResList = data.data.userResList;
              if (data.code == 0 && userResList != null && userResList.length
                  > 0) {
                // var userNum = userResList.length > 5 ? 5 : userResList.length; //资源数
                var userNum = userResList.length; //资源数
                for (var i = 0; i < userNum; i++) {
                  //图标处理
                  var iconClass = userResList[i].iconSkin;
                  if (iconClass == null || iconClass.indexOf('null') > 0) {
                    iconClass = "ztreeIcon iconfont iconicon_work";//菜单无图标时设为默认图标
                  } else {
                    iconClass = iconClass;//layui-icon
                  }

                  userResListContent +=
                      '<li>'
                      + '<a lay-href="' + serverPath.systemPath
                      + userResList[i].defaultUrl + '"> '
                      + '<i class="' + iconClass + '"></i> '
                      + '<span>' + userResList[i].resName + '</span> '
                      + '</a> '
                      + '</li>';
                }

              }
              //赋值新建删除按钮
              userResListContent +=
                  '<li id="' + addId + '">'
                  + '<a> '
                  + '<i class="ztreeIcon iconfont iconplus-square"></i> <span>新增/删除</span> '
                  + '</a>'
                  + '</li>';
            }

            $("#" + contentObj).append(userResListContent);

            //渲染弹框
            allRes(data, checkedAppId, nonCheckAppId, clickAddClass,
                clickDeleteClass);
          },
          error: function (data) {

          }

        });

        // return resData;
      }

      /**
       * 打开弹框
       */
      function openAddContent(contentObj) {
        layer.open({
          type: 1,
          title: '模块设置',
          skin: 'layui-layer-molv',
          offset: '25px',
          area: ['800px', '565px'],
          content: $('#' + contentObj)
        });
      }

      /**
       * 弹框内容
       */
      function allRes(data, resObj, nonResObj, clickAddClass,
          clickDeleteClass) {
        //初始化清空
        $("#" + nonResObj).html('');
        $("#" + resObj).html('');
        if (data != null && data.data != null) {
          if (data.code == 0) {
            var nonContent = '';
            var content = '';
            var nonUserResList = data.data.nonUserResList;
            var userResList = data.data.userResList;

            //未选择应用
            if (nonUserResList != null) {
              for (var i = 0; i < nonUserResList.length; i++) {
                nonContent +=
                    '<li class="layui-this" style="width: 150px;">'
                    + '<i class="iconfont iconplus-square ' + clickAddClass
                    + '" id="' + nonUserResList[i].resId
                    + '" style="color: #009688;margin:0 6px;"></i>'
                    + nonUserResList[i].resName
                    + '</li>';
              }
            }

            //我的应用
            if (userResList != null) {
              for (var i = 0; i < userResList.length; i++) {
                content +=
                    '<li class="layui-this" style="width: 150px">'
                    + '<i class="iconfont iconminus-square ' + clickDeleteClass
                    + '" id="' + userResList[i].resId
                    + '" style="color:#FF5722 ;margin:0 6px;"></i>'
                    + userResList[i].resName
                    + '</li> ';
              }
            }

          }
        }

        $("#" + nonResObj).append(nonContent);
        $("#" + resObj).append(content);

      }

      /**
       * 新增资源
       */
      function addRes(clickClass, conId, changeClass) {
        $(document).on("click", "." + clickClass, function () {
          // var mynum = $("#" + conId).children("li").length;
          // if (mynum < 5) {//判断是否已经有5个
          var liDom = $(this).parent()[0];//li元素
          var btnDom = $(this)[0];//这个是按钮本身
          document.getElementById(conId).appendChild(liDom);

          //将按钮的图标等换成删除的
          $(this).attr('style', 'color:#FF5722 ;margin:0 6px;');
          $(this).removeClass('iconplus-square').addClass('iconminus-square');
          $(this).removeClass(clickClass).addClass(changeClass);

          // }else{
          //     alert('我的应用最多只能添加 5 个！');
          // }

        });
      }

      /**
       * 删除资源
       */
      function deleteRes(clickClass, conId, changeClass) {
        $(document).on("click", "." + clickClass, function () {
          var liDom = $(this).parent()[0];//这个是 按钮前的标签
          var btnDom = $(this)[0];//这个是按钮本身
          document.getElementById(conId).appendChild(liDom);

          //将按钮的图标等换成添加的
          $(this).attr('style', 'color: #009688;margin:0 6px;');
          $(this).removeClass('iconminus-square').addClass('iconplus-square');
          $(this).removeClass(clickClass).addClass(changeClass);
        });
      }

      /**
       * 保存资源
       */
      function saveRes(contentObjectId, columnAlias, objId, addId,
          addContentId) {
        //触发事件
        var active = {
          sureBtn: function (othis) {
            //这里获取 所选区域的 ID
            var IDArry = new Array();　//创建一个数组

            $('#' + objId).find('i').each(function () {
              IDArry.push($(this).attr('id'));
            })

            // 保存数据
            $.ajax({
              type: 'post',
              url: '/system/sysUserColumnRes/saveUserRes',
              data: {"resIds": IDArry, "columnAlias": columnAlias},
              dataType: 'json',
              traditional: true,
              // async: false,
              success: function (data) {
                if (data != null) {
                  if (data.code == 0) {
                    //局部刷新
                    getIndexUserRes(contentObjectId, columnAlias, addId);
                    layer.close(layer.index);
                    /*layer.msg("操作成功！", {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    },function () {
                        // window.location.reload();//刷新页面
                        getIndexUserRes(contentObjectId, columnAlias, addId);
                        // layer.close(layer.index);
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    });*/
                  }
                }
              }
            });
          },
          cancelBtn: function (othis) {
            layer.close(layer.index);
          }
        };

        $('#' + addContentId + ' .site-demo-active').on('click', function () {
          var othis = $(this), type = othis.data('type');
          active[type] ? active[type].call(this, othis) : '';
        });
      }

      /**
       * 时间戳转年月日时分秒
       */
      function dateChange(date) {
        if (date.toString().indexOf("-") == -1) {
          var date = new Date(date);
          Y = date.getFullYear() + '-';
          M = ((date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1)
              : date.getMonth() + 1)) + '-';
          D = ((date.getDate() < 10) ? '0' + (date.getDate()) : date.getDate())
              + ' ';
          h = ((date.getHours() < 10) ? '0' + (date.getHours())
              : date.getHours()) + ':';
          m = ((date.getMinutes() < 10) ? '0' + (date.getMinutes())
              : date.getMinutes()) + ':';
          s = ((date.getSeconds() < 10) ? '0' + (date.getSeconds())
              : date.getSeconds()) + '';
          return Y + M + D + h + m + s;
        } else {
          return date;
        }
      }

      /**
       * 移除阴影
       */
      /*
      function moveMask(tagsel) {
          $("body > " + tagsel).remove();
          $("body").append($(tagsel));
      }*/
    });

//我的日程
if ($('#calendarOnly')) {
  layui.use(['jquery', 'totalFilter', 'commons'], function () {
    var commons = layui.commons;
    var $ = layui.jquery;
    $('#calendarOnly').html("");
    $('#calendarOnly').fullCalendar({
      locale: 'zh-cn',
      buttonText: {
        today: '今天',
        month: '月',
        week: '周',
        day: '日'
      },
      allDaySlot: true,//allday 整天的日程是否显示
      timeFormat: 'HH:mm',
      slotLabelFormat: {
        hour: 'numeric',
        hour12: false
      },
      firstDay: 1,
      defaultView: 'month',
      displayEventTime: false,
      displayEventEntTime: false,
      plugins: ['interaction', 'dayGrid', 'timeGrid'],
      //defaultDate: '2019-04-12',
      editable: false,
      selectable: true,
      eventLimit: true, // allow "more" link when too many events
      slotLabelFormat: 'HH:mm',//确定将在议程视图的垂直轴上显示的时间文本。
      slotDuration: '00:30:00',//在agenda的视图中, 两个时间之间的间隔(分钟)
      scrollTime: '08:00:00',//当切换到agenda时，初始滚动条滚动到的时间位置，默认在6点钟的位置
      nextDayThreshold: '00:00:00',//当一个事件的结束时间跨越到第二天的时间时，就像一天中的时间呈现最短的持续时间。默认：“09:00:00”（上午9点）
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
      },
      eventDrop: function (info) {
      },
      eventResize: function (info) {
      },
      eventClick: function (info) {
      },
      eventMouseEnter: function (info) {
      },
      eventMouseLeave: function (info) {
      },
      events: function (start, end, timezone, callback) {
        var view = $('#calendarOnly').fullCalendar('getView');
        var viewName = view.name;
        var url = serverPath.basePath
            + '/system/sysMySchedule/queryschedule?startDate=' + start.valueOf()
            + '&endDate=' + end.valueOf() + '&viewType=' + viewName + '&time='
            + new Date().getTime();
        $.ajax({
          type: 'post',
          url: url,
          dataType: 'json',
          success: function (result) {
            if (result.code === 1) {
              layer.alert("数据查询失败");
              return;
            }
            var events = [];
            $.each(result.data, function (i, note) {
              var title = note.scheduleName;
              var color = "#34c9df";
              if (note.scheduleUrgency == '2') {
                color = "#ff7800";
              } else if (note.scheduleUrgency == '1') {
                color = "#Fbc509";
              } else if (note.scheduleUrgency == '0') {
                color = "#75e706";
              }
              var s1 = note.scheduleStart.substring(0, 10);
              var e1 = note.scheduleEnd.substring(0, 10);
              var timeStr = "";
              if (s1 == e1) {
                var s = note.scheduleStart.substring(11).substring(0, 5);
                var e = note.scheduleEnd.substring(11).substring(0, 5);
                if (e == "00:00") {
                  e = "24:00";
                }
                timeStr = s + " - " + e + "\n"
              }
              events.push({
                id: note.id,
                title: timeStr + title,
                start: removeZero(note.scheduleStart),
                end: removeZero(note.scheduleEnd),
                backgroundColor: color
              });
            });
            callback(events);
          },
          error: function () {
            layer.alert("数据查询失败");
          }
        });
      }
    });
    String.prototype.endWith = function (str) {
      if (str == null || str == "" || this.length == 0 || str.length
          > this.length) {
        return false;
      }
      if (this.substring(this.length - str.length) == str) {
        return true;
      } else {
        return false;
      }
      return true;
    }

    /**
     * 去掉日期字符串后边的00:00,否则影响全天日程的显示效果
     * @param dateStr 日程字符串
     * @returns {string|*}
     */
    function removeZero(dateStr) {
      if (dateStr.endWith(" 00:00:00")) {
        return dateStr.substring(0, 10);
      }
      //年月日后边拼接大写字母T，否则在低版本火狐中显示有问题，只能显示全天日程
      var yyyymmdd = dateStr.substring(0, 10);
      var hhmm = dateStr.substring(11);
      dateStr = yyyymmdd + "T" + hhmm;
      return dateStr;
    }

  });
}


